package net.lastcoder.ifserver.auth;

import net.lastcoder.ifserver.Globals;
import net.lastcoder.ifserver.module.BaseModule;
import net.lastcoder.ifserver.module.ModuleNames;
import net.lastcoder.ifserver.util.ClassUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * auth: WenYF
 * date: 2016/11/15
 */
public class AuthManager extends BaseModule {
    public static final Logger Log = LoggerFactory.getLogger(AuthManager.class);
    private static AuthManager ourInstance = new AuthManager();

    public static AuthManager getInstance() {
        return ourInstance;
    }

    private AuthProvider authProvider;
    private AuthManager() {
        super(ModuleNames.AuthManager);
    }

    private void loadClass() {
        authProvider = new DefaultAuthProvider();
    }

    public void setAuthProvider(AuthProvider provider) {
        this.authProvider = provider;
    }


    @Override
    public void init() {
        loadClass();
    }

    @Override
    public void reload() {
        loadClass();
    }

    @Override
    public void destroy() {

    }

    /**
     * @param username
     * @param token
     * @return 返回false不成功
     */
    public boolean authorization(String username, String token) {
        return authProvider.authorization(username, token);
    }

}
